<template>
  <div class="app-container">
    <div class="warp_padding" v-loading="loading">  
      <div class="text_title">
       下方按钮提供老平台数据同步到新平台，请点击所需要的按钮进行数据同步操作！   
      </div>
      <el-row>
        <el-button class="el_bt1"  @click="same">区域用户数据同步</el-button>
        <el-button type="primary"  @click="same_tea"  class="mg_lt">老师用户数据同步</el-button>
        <el-button type="success"  @click="same_stu" class="mg_lt">学生用户数据同步</el-button>
        <el-button type="info"     @click="same_grp" class="mg_lt" style="background: #9a66e4;">校群数据同步</el-button>
        <el-button type="warning"  @click="same_sch" class="mg_lt">学校数据同步</el-button>
      </el-row>
    </div>
  </div>
</template>


<script>
import checkPermission from '@/utils/permission' 
import {syncareauser, syncstu, synctea} from '@/api/request'
import { syngroup,synschool } from '@/api/data'
import Config from '@/config'
import { debounce } from '@/utils/validate'
export default {
  data() {
    return {
      loading:false,
    }
  },
  methods: {
      checkPermission,
      /*same:debounce(function(){
          this.loading = true
          syncareauser().then(res=>{
              this.$message.success('区域数据同步成功'); 
              
          })
      },500),*/
      same(){
        this.loading = true
        syncareauser().then(res=>{
          setTimeout(()=> {
            this.$message({
              showClose: true,
              message: '区域数据同步成功',
              duration:1000,
              type: 'success'
            });
            this.loading = false
          }, 1000 );
        })
      },
      same_tea(){
        this.loading = true
        synctea().then(res=>{
          setTimeout(()=> {
            this.$message({
              showClose: true,
              message: '老师数据同步成功',
              duration:1000,
              type: 'success'
            });
            this.loading = false
          }, 1000 );
        })
      },
      same_stu(){
        this.loading = true
        syncstu().then(res=>{
          setTimeout(()=> {
            this.$message({
              showClose: true,
              message: '学生数据同步成功',
              duration:1000,
              type: 'success'
            });
            this.loading = false
          }, 1000 );
        })
      },
      same_grp(){
        this.loading = true
        syngroup(Config.cityCode).then(res=>{
          if (res.code == 2000) {
            setTimeout(()=> {
              this.$message({
                showClose: true,
                message: '校群数据同步成功',
                duration:1000,
                type: 'success'
              });
              this.loading = false
            }, 1000 );
            return  
          }else{
            this.loading = false
            this.$message.error('同步成功失败'); 
          }
        })
      },
      same_sch(){
        this.loading = true
        synschool(Config.cityCode).then(res=>{
          if (res.code == 2000) {
            setTimeout(()=> {
              this.$message({
                showClose: true,
                message: '学校数据同步成功',
                duration:1000,
                type: 'success'
              });
              this.loading = false
            }, 1000 );
           return
          }else{
            this.loading = false
            this.$message.error('同步成功失败'); 
          }
        })
      },
      
  }
}
</script>

<style lang="scss" scoped>
.text_title{
    font-size:16px;
    margin:20px 0;
    text-align: center;
    color:#888;
}
.el-row{
    max-width:550px;
    margin:0 auto;
    .el_bt1{
        background: rgb(255, 153, 0);
        color:#fff;
        &:hover{
            background:#ef9611;
        }
    }
    .el-button{
        height:120px;
        width:100%;
    }
    .mg_lt{
        margin-left: 0px;
        margin-top:20px;
    }
}

</style>
